use crate::vue_parser::models::ScriptInfo;
use crate::vue_parser::VueParser;

#[test]
fn test_get_template() {
    let vue_content = r#"
<template>
  <p>Hello</p>
</template>
<script>
</script>
<style scoped>
</style>
"#;
    let result = VueParser::get_template(vue_content).unwrap();
    let target = vue_content[result.content_start_index..result.content_end_index].to_string();
    assert_eq!(
        target,
        r#"
  <p>Hello</p>
"#
    );
}

const VUE_CONTENT1: &str = r#"

    <template>
      <view style="background-color: #f7f7f6">
      <!--cli:custom-header-->
    <SearchHeader @messageHeaderClick="handleMessageHeaderClick" />
    <!--/cli:custom-header-->
    <!-- 搜索部分 -->
    <!-- banner图 -->
    </view>
</template>
<script>
export default {

    metohds: {
      handleClick(){
        this.$emit("handleMessageHeaderClick", "params")
      },
      handleClick1(){
        this.$emit("handleMessageHeaderClick", "params")
      },
      handleClick2(){
        this.$emit("handleMessageHeaderClick1", "params")
      }
    }

}
</script>
<style>
</style>
"#;

#[test]
fn test_get_cli_tag() {
    let template = VueParser::get_template(VUE_CONTENT1).unwrap();
    let tag_info = template.get_cli_tag("custom-header").unwrap();
    assert_eq!(
        VUE_CONTENT1[tag_info.start_index..tag_info.end_index].to_string(),
        r#"<!--cli:custom-header-->
    <SearchHeader @messageHeaderClick="handleMessageHeaderClick" />
    <!--/cli:custom-header-->"#
    );

    assert_eq!(
        VUE_CONTENT1[tag_info.inner_start_index..tag_info.inner_end_index].to_string(),
        r#"
    <SearchHeader @messageHeaderClick="handleMessageHeaderClick" />
    "#
    );
}
#[test]
fn test_set_cli_tag() {
    let template = VueParser::get_template(VUE_CONTENT1).unwrap();
    let tag_info = template.get_cli_tag("custom-header");
    assert_eq!(
        template
            .set_tag_content(tag_info.as_ref(), "<MessageHeader/>")
            .unwrap(),
        r#"

    <template>
      <view style="background-color: #f7f7f6">
      <!--cli:custom-header--><MessageHeader/><!--/cli:custom-header-->
    <!-- 搜索部分 -->
    <!-- banner图 -->
    </view>
</template>
<script>
export default {

    metohds: {
      handleClick(){
        this.$emit("handleMessageHeaderClick", "params")
      },
      handleClick1(){
        this.$emit("handleMessageHeaderClick", "params")
      },
      handleClick2(){
        this.$emit("handleMessageHeaderClick1", "params")
      }
    }

}
</script>
<style>
</style>
"#
    );
}

#[test]
fn test_get_script_events() {
    let script_info = VueParser::get_script(VUE_CONTENT1).unwrap();
    let events = script_info.events();
    assert!(events.contains(&"handleMessageHeaderClick".to_string()));
    assert!(events.contains(&"handleMessageHeaderClick1".to_string()));
}
